package cn.micai.base.lambda;

import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * 描述：
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/6/21 17:47
 */
public class ArrayToStreamExample {

    public static void main(String [] args) {

        String [] arrays = {"a", "b", "c", "d", "e"};

        // Arrays.stream
        Stream<String> stream = Arrays.stream(arrays);
        stream.forEach(x -> System.out.println(x));

        // Stream.of
        Stream<String> stream2 = Stream.of(arrays);
        stream2.forEach(x -> System.out.println(x));

        int[] nums = {1,2,3,4,5};

        // Arrays.stream -> IntStream
        IntStream intStream1 = Arrays.stream(nums);
        intStream1.forEach(x->System.out.println(x));

        // Stream.of -> Stream<int[]>
        Stream<int[]> temp = Stream.of(nums);

        // Cant print Stream<int[]> directly, convert / flat it to IntStream
        IntStream intStream2 = temp.flatMapToInt(x -> Arrays.stream(x));
        intStream2.forEach(x->System.out.println(x));

        String fucking_str = "aa_bb_xx_yy_cc";
        fucking_str = fucking_str.replaceAll("aa_bb_([^\\ ]+)_([^\\ ]+)_cc", "$1_$2");
        System.out.println(fucking_str);

    }
}
